<?php
/**
 * Copyright (c) 2018. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

/**
 * 自动脚本服务类型
 * Created by PhpStorm.
 * User: poptser
 * Date: 2017/4/6
 * Time: 13:40
 */

namespace SDXApi\Controller;
use Think\Controller;
use Think\Model;

class AutoserverController extends Controller
{


    public function index(){
        set_time_limit(0);
        header("Content-type: text/html; charset=utf-8");


        $input_data = I("get.date");

        if(empty($input_data)){
            $darta = date('Y-m-01');
            $input_data = date('Y-m');
            echo "<h2>未输入月份，默认显示本月数据：".$input_data."</h2>";
        }else{
            if(date("Y-m",strtotime($input_data))==$input_data){
                $darta = $input_data;
                echo "<h2>为你显示数据：".$input_data."</h2>";
            }else{
                $input_data = date('Y-m');
                echo "<h2>输入数据错误，为你显示本月数据：".$input_data."</h2>";
                $darta = date('Y-m-01');
            }
        }

        echo "<h3>访问其它月份数据 http://api.shidexian.com/index.php?s=Autoserver/index/date/<span style='color: #ff0000'>".$input_data."</span>,修改此链接红色部分</h3>";

        $firstday = date('Y-m-01', strtotime($darta));
        $lastday = date('Y-m-01', strtotime($darta." +1 month"));

        $start_time = strtotime($firstday)-28800;
        $end_time = strtotime($lastday)-28800;

        $order_info = M("order_info")->field("outgo_time,best_time_start,
        best_time,pay_time,outgo_id,order_id,wdr_id,order_sn")->
        where("pay_status IN (2,3) AND order_status !=2 AND 196_admin_id = 0 AND
      shipping_status = 2 AND outgo_id !=0 AND shipping_id = 3 AND
      pay_time > ".$start_time." AND pay_time < ".$end_time)->select();

        $wdr = array();
        $name = array();
        $user_name = array();

        foreach ($order_info as $key=>$value){
            //配送物流点
            if(empty($wdr[$value['wdr_id']])){
                $order_info[$key]['logistics_point_info'] =
                    M("warehouse_deliver_region")->where("id = ".$value['wdr_id'])
                        ->getField("name");
                $wdr[$value['wdr_id']] = $order_info[$key]['logistics_point_info'];
            }else{
                $order_info[$key]['logistics_point_info'] = $wdr[$value['wdr_id']];
            }

            //出仓员信息
//            if(empty($name[$value['outgo_id']])){
//                $order_info[$key]['dis_name'] = M("warehouse_personnel")->where("uid = ".$value['outgo_id'])
//                    ->getField("name");
//                $name[$value['outgo_id']] = $order_info[$key]['dis_name'];
//            }else{
//                $order_info[$key]['dis_name'] = $name[$value['outgo_id']];
//            }

            if(empty($user_name[$value['outgo_id']])){
                $order_info[$key]['dis_login'] = M("admin_user")->where("user_id = ".$value['outgo_id'])
                    ->getField("user_name");
                $user_name[$value['outgo_id']] = $order_info[$key]['dis_login'];
            }else{
                $order_info[$key]['dis_login'] = $user_name[$value['outgo_id']];
            }


            //送达时间
            $order_info[$key]['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']+28800);
            //期望时间
            $order_info[$key]['best_time'] = date('Y-m-d H:i',$value['best_time_start'])." - ".date('H:i',$value['best_time']);
            //出仓时间
            $order_info[$key]['outgo_time'] = date('Y-m-d H:i',$value['outgo_time']+28800);




        }

        echo "<table border='1'>
            <tr>
                <td>序列</td>
                <td>订单号</td>
                <td>下单时间</td>
                <td>配送物流点</td>
                <td>期望送达</td>
                <td>出仓时间</td>
                <td>出仓账号</td>
            </tr>";

        foreach ($order_info as $key=>$value){
            echo "
            <tr>
                <td>".$key."</td>  <!--序列-->
                <td>".$value['order_sn']."</td><!--订单号-->
                <td>".$value['pay_time']."</td><!--下单时间-->
                <td>".$value['logistics_point_info']."</td><!--配送物流点-->
                <td>".$value['best_time']."</td><!--期望送达-->
                <td>".$value['outgo_time']."</td><!--出仓时间-->
                <td>".$value['dis_login']."</td><!--出仓账号-->
            </tr>";
        }

        echo "</table>";
    }

    public function ph(){
        set_time_limit(0);
        header("Content-type: text/html; charset=utf-8");


        $input_data = I("get.date");

        if(empty($input_data)){
            $darta = date('Y-m-01');
            $input_data = date('Y-m');
            echo "<h2>未输入月份，默认显示本月数据：".$input_data."</h2>";
        }else{
            if(date("Y-m",strtotime($input_data))==$input_data){
                $darta = $input_data;
                echo "<h2>为你显示数据：".$input_data."</h2>";
            }else{
                $input_data = date('Y-m');
                echo "<h2>输入数据错误，为你显示本月数据：".$input_data."</h2>";
                $darta = date('Y-m-01');
            }
        }

        echo "<h3>访问其它月份数据 http://api.shidexian.com/index.php?s=Autoserver/ph/date/<span style='color: #ff0000'>".$input_data."</span>,修改此链接红色部分</h3>";

        $firstday = date('Y-m-01', strtotime($darta));
        $lastday = date('Y-m-01', strtotime($darta." +1 month"));

        $start_time = strtotime($firstday)-28800;
        $end_time = strtotime($lastday)-28800;

        $user_id = M("users")->where("user_name NOT LIKE 'wx_196%'")->getField("user_id",true);
        //dump($user_id);

        $where = "pay_status IN (2,3) AND order_status !=2 AND 196_admin_id = 0 AND
      shipping_status = 2 AND shipping_id = 3 AND wdr_id != 0 AND user_id IN (".implode(',',$user_id).") AND
      pay_time > ".$start_time." AND pay_time < ".$end_time;

        $quality_array_user = M("order_info")->field("order_id,sorting_id,wid")->
        where($where)->select();

//        $sorting_array_user = M("order_info")->
//        where($where)->group('sorting_id')->getField("sorting_id",true);

        $quality_array = array();
        foreach ($quality_array_user as $value){
            if($quality_array[$value['sorting_id']][$value['wid']]){
                $quality_array[$value['sorting_id']][$value['wid']]++;
            }else{
                $quality_array[$value['sorting_id']][$value['wid']] = 1;
            }
        }



        $quality_array_user = array();
        foreach ($quality_array as $key=>$value){
            $quality_array_user[] = array(
                "user_id" =>$key,
                "name" =>M("admin_user")->where("user_id = ".$key)
                    ->getField("user_name"),
                "num8" => $value[8],
                "num17" => $value[17],
                "num18" => $value[18],
            );
        }

        echo "<table border='1'>
            <tr>
                <td>ID</td>
                <td>姓名</td>
                <td>高志体验店</td>
                <td>海珠体验店</td>
                <td>白云体验店</td>
            </tr>";

        foreach ($quality_array_user as $key=>$value){
            echo "
            <tr>
                <td>".$value['user_id']."</td>  <!--序列-->
                <td>".$value['name']."</td><!--订单号-->
                <td>".$value['num8']."</td><!--下单时间-->
                <td>".$value['num17']."</td><!--下单时间-->
                <td>".$value['num18']."</td><!--下单时间-->
            </tr>";
        }

        echo "</table>";
    }


    public function zj(){

        set_time_limit(0);
        header("Content-type: text/html; charset=utf-8");


        $input_data = I("get.date");

        if(empty($input_data)){
            $darta = date('Y-m-01');
            $input_data = date('Y-m');
            echo "<h2>未输入月份，默认显示本月数据：".$input_data."</h2>";
        }else{
            if(date("Y-m",strtotime($input_data))==$input_data){
                $darta = $input_data;
                echo "<h2>为你显示数据：".$input_data."</h2>";
            }else{
                $input_data = date('Y-m');
                echo "<h2>输入数据错误，为你显示本月数据：".$input_data."</h2>";
                $darta = date('Y-m-01');
            }
        }

        echo "<h3>访问其它月份数据 http://api.shidexian.com/index.php?s=Autoserver/zj/date/<span style='color: #ff0000'>".$input_data."</span>,修改此链接红色部分</h3>";

        $firstday = date('Y-m-01', strtotime($darta));
        $lastday = date('Y-m-01', strtotime($darta." +1 month"));

        $start_time = strtotime($firstday)-28800;
        $end_time = strtotime($lastday)-28800;


        $user_id = M("users")->where("user_name NOT LIKE 'wx_196%'")->getField("user_id",true);
        //dump($user_id);

        $where = "pay_status IN (2,3) AND order_status !=2 AND 196_admin_id = 0 AND
      shipping_status = 2 AND shipping_id = 3 AND wdr_id != 0 AND user_id IN (".implode(',',$user_id).") AND
      pay_time > ".$start_time." AND pay_time < ".$end_time;

        $quality_array_user = M("order_info")->field("order_id,quality_id,wid")->
        where($where)->select();

//        $sorting_array_user = M("order_info")->
//        where($where)->group('sorting_id')->getField("sorting_id",true);

        $quality_array = array();
        foreach ($quality_array_user as $value){
            if($quality_array[$value['quality_id']][$value['wid']]){
                $quality_array[$value['quality_id']][$value['wid']]++;
            }else{
                $quality_array[$value['quality_id']][$value['wid']] = 1;
            }
        }



        $quality_array_user = array();
        foreach ($quality_array as $key=>$value){
            $quality_array_user[] = array(
                "user_id" =>$key,
                "name" =>M("admin_user")->where("user_id = ".$key)
                    ->getField("user_name"),
                "num8" => $value[8],
                "num17" => $value[17],
                "num18" => $value[18],
            );
        }

        echo "<table border='1'>
            <tr>
                <td>ID</td>
                <td>姓名</td>
                <td>高志体验店</td>
                <td>海珠体验店</td>
                <td>白云体验店</td>
            </tr>";

        foreach ($quality_array_user as $key=>$value){
            echo "
            <tr>
                <td>".$value['user_id']."</td>  <!--序列-->
                <td>".$value['name']."</td><!--订单号-->
                <td>".$value['num8']."</td><!--下单时间-->
                <td>".$value['num17']."</td><!--下单时间-->
                <td>".$value['num18']."</td><!--下单时间-->
            </tr>";
        }

        echo "</table>";
    }





    /**
     * 定时发送订单给指定邮箱
     */
    public function order_send(){
        $item_list = M("alarm")->find();

        $no_ready = $item_list['no_ready'];                   //未配货预警时间
        $no_distribution = $item_list['no_distribution'];     //未配送预警时间
        $distribution = $item_list['distribution'];           //未送达预警时间




        //dump($order_info);

        //date("H:i")=="09:00"||date("H:i")=="14:00"||date("H:i")=="00:00"
        if(date("H:i")=="09:00"||date("H:i")=="14:00"||date("H:i")=="00:00"){

            $send_mail = M("shop_config")->where(array("code"=>"order_send_mail"))->getField("value");
            if(empty($send_mail)){
                //无邮箱地址，停止运行
                return false;
            }
            $file_dir_ok = array();
            //发送当天 未配货、未出仓、未配送、未送达的订单
            $order_info = $this->serch_un_match_order($no_ready);         //未配货
            if($order_info){
                $file_dir1 = "order_xls/alarm/weipeihuo".date("Ymd")."_".rand(00000,99999);
                $excel_file= $this->download_user_excel($order_info,$file_dir1);
                if($excel_file){
                    //发送文件
                    $file_dir_ok[] = $file_dir1.".xls";
                    $order_send_data[] =  array(
                        "order_type" => 1,
                        "file_dir" => $file_dir1.".xls",
                        "send_time" => gmtime(),
                        "email" => $send_mail
                    );
                }
            }
            $order_info = $this->serch_un_leave_warehouse($no_ready);         //未出仓
            if($order_info){
                $file_dir2 = "order_xls/alarm/weichucang".date("Ymd")."_".rand(00000,99999);
                $excel_file= $this->download_user_excel($order_info,$file_dir2);
                if($excel_file){
                    //发送文件
                    $file_dir_ok[] = $file_dir2.".xls";
                    $order_send_data[] =  array(
                        "order_type" => 2,
                        "file_dir" => $file_dir2.".xls",
                        "send_time" => gmtime(),
                        "email" => $send_mail
                    );
                }
            }
            $order_info = $this->serch_un_distribution($no_distribution);      //未配送
            if($order_info){
                $file_dir3 = "order_xls/alarm/weipeisong".date("Ymd")."_".rand(00000,99999);
                $excel_file= $this->download_user_excel($order_info,$file_dir3);
                if($excel_file){
                    //发送文件
                    $file_dir_ok[] = $file_dir3.".xls";
                    $order_send_data[] =  array(
                        "order_type" => 3,
                        "file_dir" => $file_dir3.".xls",
                        "send_time" => gmtime(),
                        "email" => $send_mail
                    );
                }
            }
            $order_info = $this->serch_un_take_delivery($distribution);         //未送达
            if($order_info){
                $file_dir4 = "order_xls/alarm/weisongda".date("Ymd")."_".rand(00000,99999);
                $excel_file= $this->download_user_excel($order_info,$file_dir4);
                if($excel_file){
                    //发送文件
                    $file_dir_ok[] = $file_dir4.".xls";
                    $order_send_data[] =  array(
                        "order_type" => 4,
                        "file_dir" => $file_dir4.".xls",
                        "send_time" => gmtime(),
                        "email" => $send_mail
                    );
                }
            }

            if (count($file_dir_ok)>0){
                //发送邮件
                M("order_send_log")->addAll($order_send_data);
                $this->send_mail($send_mail,"订单预警信息","",$file_dir_ok);
            }
        }
    }


    /**
     * 在22:00 9:00 14:00 发送 配送区域在 一日两送外派区 的订单到指定邮箱
     * 22:00  发送次日订单  9:00 14:00 发送当日订单
     */
    public function order_send_region(){
        $where = null;
        //$where= "o.shipping_status !=2 and o.pay_status in (2,3) and o.order_status <>2  and o.shipping_id = 3 and TO_DAYS(from_unixtime(o.best_time))=TO_DAYS(NOW()) and o.wdr_id = wdr.id and wdr.wdtype = 16";
        if(date("H:i")=="09:00"||date("H:i")=="14:00"){
            $where= "o.shipping_status !=2 and o.pay_status in (2,3) and o.order_status <>2  and o.shipping_id = 3 and TO_DAYS(from_unixtime(o.best_time))=TO_DAYS(NOW()) and o.wdr_id = wdr.id and wdr.wdtype = 16";
        }elseif(date("H:i")=="22:00"){
            $where= "o.shipping_status !=2 and o.pay_status in (2,3) and o.order_status <>2  and o.shipping_id = 3 and (TO_DAYS(from_unixtime(o.best_time))=TO_DAYS(DATE_SUB(CURDATE(),INTERVAL -1 DAY)) or TO_DAYS(from_unixtime(o.best_time))=TO_DAYS(NOW())) and o.wdr_id = wdr.id and wdr.wdtype = 16";

        }
        if ($where){
            $this->get_order_by_where_region($where);
        }
    }


    /**
     * 根据条件查询番禺，海珠的订单
     * @param $where
     */
    private function get_order_by_where_region($where){
        $order_info = M()->table(array('sdx_order_info'=>'o','sdx_warehouse_deliver_region'=>'wdr'))
            ->where($where)->select();

        foreach ($order_info as $key=>$value){
            $goods_info = $this->get_goods_list_real($value['order_id'],false,"name");
            $order_info[$key]['goods_name'] = $goods_info['goods_name'];
            $order_info[$key]['goods_weight'] = $goods_info['goods_weight'];
            $order_info[$key]['goods_num'] = $goods_info['goods_num'];
            $order_info[$key]['address'] = $this->get_address_desc($value['province'], $value['city'], $value['district']).$value['address'].$value['address_name'];
            $order_info[$key]['best_time'] = date("Y-m-d H:i:s",$value['best_time']);
            $order_info[$key]['best_time_start'] = date("Y-m-d H:i:s",$value['best_time_start']);
        }
        if($order_info){
            $file_dir1 = "order_xls/region/".date("Ymd")."_".rand(00000,99999);
            $excel_file= $this->download_user_excel_region($order_info,$file_dir1);
            if($excel_file){
                //发送文件
                $file_dir_ok[] = $file_dir1.".xls";
                $order_send_data =  array(
                    "order_type" => 5,
                    "file_dir" => $file_dir1.".xls",
                    "send_time" => gmtime(),
                    "email" => "GZ3send@163.com mnwtt@qq.com 510683894@qq.com"
                );
                M("order_send_log")->add($order_send_data);
                $this->send_mail_region("食得鲜订单信息","",$file_dir_ok);
            }
        }

    }






    /**
     * 查询未配货的预警订单
     * 需要字段 订单号、收货人、电话、收货地址、标志性建筑、所属区域、所属划区、配送时间、商品种类
     */
    public function serch_un_match_order($early_time=null){
        $where= "pay_status in (2,3) and order_status <>2 and shipping_status IN (0,3) and shipping_id = 3";
        return $this->get_order_by_where($where,"未配货");
    }

    /**
     * 查询未出仓的预警订单
     */
    public function serch_un_leave_warehouse($early_time=null){
        $where= "order_status !=2 and  shipping_status = 5  and outgo = 0 and shipping_id = 3 and sorting_id !=0";   //已发货的送货上门订单，超出时间范围
        return $this->get_order_by_where($where,"未出仓");
    }

    /**
     * 查询未配送的预警订单
     * @param null $early_time
     * @return bool
     */
    public function serch_un_distribution($early_time=null){
        if(empty($early_time)){
            return false;
        }
        $where ="outgo = 1 and shipping_status = 5 and sorting_id <>0 and order_status <> 2 and shipping_id = 3 and pay_status in(2,3) and sorting_time<".(gmtime()-$early_time);
        return $this->get_order_by_where($where,"未配送");
    }

    /**
     * 查询收货确认的预警订单
     * @param null $early_time
     * @return bool|mixed
     */
    public function serch_un_take_delivery($early_time=null){
        if(empty($early_time)){
            return false;
        }
        $where ="shipping_status = 1  and order_status =5 and shipping_id = 3 and shipping_time <> 0 and shipping_time <".(gmtime()-$early_time);

        return $this->get_order_by_where($where,"未送达");

    }

    /**
     * 根据条件查询订单所需信息
     * @param null $where
     * @param null $where_title
     * @return bool|mixed
     */
    public function get_order_by_where($where=null, $where_title=null){
        if(empty($where)||empty($where_title)){
            return false;
        }
        $order_info = M("order_info")->field("mobile,order_id,order_sn,consignee,province,city,district,address,sign_building,best_time,best_time_start,wdr_id,wid")
            ->where($where)->select();

        if($order_info){
            foreach ($order_info as $key=>$value){
                $region_name = M("warehouse_deliver_region")->field("name,zoning_id")->where(array("id"=>$value['wdr_id']))->find();
                $order_info[$key]['address'] = $this->get_address_desc($value['province'], $value['city'], $value['district']).$value['address'].$value['address_name'];
                $order_info[$key]['precincts'] = $region_name['name'];
                $order_info[$key]['region'] = M("zoning_cate")->where(array("id"=>$region_name['zoning_id']))->getField("name");
                $order_info[$key]['type'] = $where_title;
                $order_info[$key]['best_time'] = date("Y-m-d H:i:s",$value['best_time']);
                $order_info[$key]['best_time_start'] = date("Y-m-d H:i:s",$value['best_time_start']);
                $goods_info= $this->get_goods_list_real($value['order_id'],false,"name");
                $order_info[$key]['goods_info'] = $goods_info['goods_name'];
            }
            return $order_info;
        }else{
            return false;
        }
    }
    /**
     * 根据订单ID获取订单里面的原始商品（未退款之前的）
     * rui
     * @param $order_id
     * @return mixed
     */
    private function get_goods_list_by_order($order_id,$no_gift=false){
        if($no_gift){
            $where['order_id'] = $order_id;
            $where['giving'] = array("neq",1);
            return M("order_goods")->where($where)->select();
        }else{
            return M("order_goods")->where(array("order_id"=>$order_id))->select();
        }

    }

    /**
     * 查询订单的退款商品记录
     * rui
     * @param $order_id
     * @return mixed
     */
    private function get_refund_goods_list($order_id){
        $refund_detail = M("refund_detail")->field("order_goods_id,sum(refund_number) as refund_number ,sum(surplus_number) as surplus_number,goods_id,goods_name,goods_sn ")->where(array("order_id"=>$order_id))->group('order_goods_id')->select();
        //dump(M("refund_detail")->getlastsql());
        return $refund_detail;
    }

    /**
     * TODO 获取订单内剩余商品数
     * rui
     * @param $order_id
     * @return mixed
     */
    public function get_goods_list_real($order_id,$no_gift =  false,$type="name"){
        $buy_goods_list = $this->get_goods_list_by_order($order_id,$no_gift);
        //dump($buy_goods_list);

        $refund_goods_list = $this->get_refund_goods_list($order_id);

        foreach ($buy_goods_list as $key=>$value){
            $buy_goods_list[$key]['cat_id'] = M("goods")->where(array("goods_id"=>$value['goods_id']))->getField('cat_id');
            $edit_goods = true;
            foreach ($refund_goods_list as $key2=>$value2){
                if($value['rec_id']==$value2['order_goods_id']){
                    $buy_goods_list[$key]['real_num'] = $value['goods_number']-$value2['refund_number'];
                    $edit_goods = false;
                }
            }
            if($edit_goods){
                $buy_goods_list[$key]['real_num'] = $value['goods_number'];
            }
            if($buy_goods_list[$key]['real_num']==0){
                unset($buy_goods_list[$key]);
            }
        }
        $i=0;
        $goods_str = array();
        foreach ($buy_goods_list as $key=>$value){
            if($i==0){
                $goods_str['goods_name'] .=$value['goods_name'];
            }else{
                $goods_str['goods_name'] .="\n".$value['goods_name'];
            }
            $goods_str['goods_num'] +=$value['real_num'];
            $goods_str['goods_weight'] +=$value['real_num']*M("goods")->where(array("goods_id"=>$value['goods_id']))->getField("goods_weight");
            $i++;
        }
        return $goods_str;
    }
    /**
     * 获取地址信息
     * rui poptser@foxmail.com 2016-10-11 09:30:20
     * @param $country
     * @param $province
     * @param $city
     * @param $district
     * @return string
     */
    public function get_address_desc($province, $city, $district){
        $province_name=$this->get_region_name($province);
        $city_name=$this->get_region_name($city);
        $district_name=$this->get_region_name($district);
        return $province_name.$city_name.$district_name;
    }
    /*TODO 根据ID获取区域对应名称*/
    public  function get_region_name($id){
        $res=M('region')->where(array('region_id'=>$id))->find();
        return $res['region_name'];
    }
    /**
     * 导出数据到服务器
     * @param $data
     * @param string $name
     */
    public function download_user_excel_region($data,$name='Excel')
    {
        import('Vendor.PHPExcel.PHPExcel');
        import('Vendor.PHPExcel.PHPExcel.Writer.Excel5');
        import('Vendor.PHPExcel.PHPExcel.IOFactory');
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->getProperties()->setCreator("shidexian@youguoshu")
            ->setLastModifiedBy("shidexian@youguoshu")
            ->setTitle("download file shidexian@youguoshu")
            ->setSubject("shidexian@youguoshu")
            ->setDescription("shidexian@youguoshu")
            ->setKeywords("shidexian")
            ->setCategory("shidexian");

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(5);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(10);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(60);
        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle( 'A1:K1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
        $objPHPExcel->getActiveSheet()->getStyle( 'A1:K1')->getFill()->getStartColor()->setARGB('FFF1A325');

        $objPHPExcel->getActiveSheet()->getStyle('A:K')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);

        $styleArray = array(
            'borders' => array(
                'allborders' => array(
                    'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
                ),
            ),
        );

        $objPHPExcel->setActiveSheetIndex(0)
            //Excel的第A列，uid是你查出数组的键值，下面以此类推
            ->setCellValue('A1','订单编号')
            ->setCellValue('B1','产品名称')
            ->setCellValue('C1','规格(kg)')
            ->setCellValue('D1','数量')
            ->setCellValue('E1','客人姓名')
            ->setCellValue('F1','电话')
            ->setCellValue('G1','区域')
            ->setCellValue('H1','地址')
            ->setCellValue('I1','标志性建筑')
            ->setCellValue('J1','送达时间范围')
            ->setCellValue('K1','备注');
        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(30);
        $objPHPExcel->getActiveSheet()->getStyle('A1:K1')->applyFromArray($styleArray);

        foreach ($data as $k => $v) {
            $num = $k + 2;
            $objPHPExcel->getActiveSheet()->getRowDimension($num)->setRowHeight(30);
            $objPHPExcel->getActiveSheet()->getStyle('A'.$num.':K'.$num)->applyFromArray($styleArray);
            $objPHPExcel->getActiveSheet()->getStyle('B'.$num)->getAlignment()->setWrapText(true);
            $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValueExplicit('A' . $num, $v['order_sn'],\PHPExcel_Cell_DataType::TYPE_STRING)
                ->setCellValue('B' . $num, $v['goods_name'])
                ->setCellValueExplicit('C' . $num, $v['goods_weight'],\PHPExcel_Cell_DataType::TYPE_STRING)
                ->setCellValue('D' . $num, $v['goods_num'])
                ->setCellValue('E' . $num, $v['consignee'])
                ->setCellValue('F' . $num, $v['mobile'])
                ->setCellValue('G' . $num, $v['name'])
                ->setCellValue('H' . $num, $v['address'])
                ->setCellValue('I' . $num, $v['sign_building'])
                ->setCellValue('J' . $num, $v['best_time_start']."-".$v['best_time'])
                ->setCellValue('K' . $num, $v['postscript']);
        }
        $line_num = $num+1;
        $objPHPExcel->getActiveSheet()->mergeCells('A'.$line_num.':K'.$line_num);
        $objPHPExcel->getActiveSheet()->setCellValue('A'.$line_num, "食得鲜订单信息,订单数据截至".date('y-m-d h:i:s',time())." 广州优果蔬网络科技有限公司");
        $objPHPExcel->getActiveSheet()->getStyle('A'.$line_num)->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->setTitle('User');
        $objPHPExcel->setActiveSheetIndex(0);
        $write = new \PHPExcel_Writer_Excel5($objPHPExcel);
        $write->save($name.'.xls');
        return true;
    }
    /**
     * 导出数据到服务器
     * @param $data
     * @param string $name
     */
    public function download_user_excel($data,$name='Excel')
    {
        import('Vendor.PHPExcel.PHPExcel');
        import('Vendor.PHPExcel.PHPExcel.Writer.Excel5');
        import('Vendor.PHPExcel.PHPExcel.IOFactory');
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->getProperties()->setCreator("shidexian@youguoshu")
            ->setLastModifiedBy("shidexian@youguoshu")
            ->setTitle("download file shidexian@youguoshu")
            ->setSubject("shidexian@youguoshu")
            ->setDescription("shidexian@youguoshu")
            ->setKeywords("shidexian")
            ->setCategory("shidexian");

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(50);
        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getStyle('A1:J1')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle( 'A1:J1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
        $objPHPExcel->getActiveSheet()->getStyle( 'A1:J1')->getFill()->getStartColor()->setARGB('FFF1A325');

        $objPHPExcel->getActiveSheet()->getStyle('A:J')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);

        $styleArray = array(
            'borders' => array(
                'allborders' => array(
                    'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
                ),
            ),
        );

        $objPHPExcel->setActiveSheetIndex(0)
            //Excel的第A列，uid是你查出数组的键值，下面以此类推
            ->setCellValue('A1','订单号')
            ->setCellValue('B1','收货人')
            ->setCellValue('C1','电话')
            ->setCellValue('D1','收货地址')
            ->setCellValue('E1','标志建筑')
            ->setCellValue('F1','所属区域')
            ->setCellValue('G1','所属划区')
            ->setCellValue('H1','配送时间')
            ->setCellValue('I1','商品种类')
            ->setCellValue('J1','订单类型');
        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(30);
        $objPHPExcel->getActiveSheet()->getStyle('A1:E1')->applyFromArray($styleArray);

        foreach ($data as $k => $v) {
            $num = $k + 2;
            $objPHPExcel->getActiveSheet()->getRowDimension($num)->setRowHeight(30);
            $objPHPExcel->getActiveSheet()->getStyle('A'.$num.':J'.$num)->applyFromArray($styleArray);
            $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValueExplicit('A' . $num, $v['order_sn'],\PHPExcel_Cell_DataType::TYPE_STRING)
                ->setCellValue('B' . $num, $v['consignee'])
                ->setCellValueExplicit('C' . $num, $v['mobile'],\PHPExcel_Cell_DataType::TYPE_STRING)
                ->setCellValue('D' . $num, $v['address'])
                ->setCellValue('E' . $num, $v['sign_building'])
                ->setCellValue('F' . $num, $v['precincts'])
                ->setCellValue('G' . $num, $v['region'])
                ->setCellValue('H' . $num, $v['best_time_start']."-".$v['best_time'])
                ->setCellValue('I' . $num, $v['goods_info'])
                ->setCellValue('J' . $num, $v['type']);
        }
        $line_num = $num+1;
        $objPHPExcel->getActiveSheet()->mergeCells('A'.$line_num.':J'.$line_num);
        $objPHPExcel->getActiveSheet()->setCellValue('A'.$line_num, "食得鲜订单预警信息".$name);
        $objPHPExcel->getActiveSheet()->getStyle('A'.$line_num)->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->setTitle('User');
        $objPHPExcel->setActiveSheetIndex(0);
        $write = new \PHPExcel_Writer_Excel5($objPHPExcel);
        $write->save($name.'.xls');
        return true;
    }

    /**
     * poptser 附带附件
     * 邮件发送
     */
    public function send_mail_region($title=null,$body=null,$file=null){



        $mailbody = "
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<tbody><tr>
  <td bgcolor='#EFF2F7' align='center' style='padding:22px 0 36px 0;' class='padding5'>
  <table border='0' cellpadding='0' cellspacing='0' style='border-radius:4px; margin:0 auto; background-color:#ffffff' width='650' class='responsive-table'>
    <tbody>
    <tr>
      <td style='background-color:#ffffff; padding:0 50px 45px 50px;' class='padding1'>
        <table border='0' cellpadding='0' cellspacing='0' width='100%'>
           <tbody><tr>
             <td bgcolor='#ffffff' align='middle' style='background-color:#ffffff; font-size: 22px; color:#303C4B; font-weight:bold; padding:0 0 40px 0; line-height:32px;' colspan='2' class='padding4'>
               <span class='title' style='padding-bottom: 5px; border-bottom: 5px solid #ffd900;'>订单自动发送信息</span>
             </td>
          </tr>
          <tr>
             <td class='padding7' bgcolor='#ffffff' align='left' style='background-color:#ffffff; font-size: 15px; color:#4C5764; line-height:27px;' colspan='2'>
             相关内容请下载附件查看<br>
             此邮件自动发送，请勿回复此邮件<br>
             为确保收到邮件，请将“admin@shidexian.com”加入白名单<br>
             </td>
          </tr>
        </tbody></table>
      </td>
    </tr>
        <tr>
      <td align='center' class='padding'>
        <table border='0' cellspacing='0' cellpadding='0' class='responsive-table'>
          <tbody><tr>
            <td>
              <span style='font-family:Hiragino Sans GB;font-size:16px;'>
              <a style='text-decoration:none;color:#ffffff;' href='##' target='_blank'>
               <div style='padding:10px 29px 10px 29px;border-radius:5px;text-align:center;text-decoration:none;background-color:#2bbdf8;color:#ffffff;font-size:20px;margin:0;white-space:nowrap'>食得鲜@广州优果蔬网络科技有限公司</div>
              </a>
              </span>
              <br>
            </td>
          </tr>
        </tbody></table>
      </td>
    </tr>
      </tbody></table>
    </td>
    </tr>
</tbody></table>
</td>
</tr>
</tbody></table>
                ";//邮件内容
        import('Vendor.smtp_new');
        $mail = new \MySendMail();
        $mail->setServer("smtp.ym.163.com", "admin@shidexian.com", "sdxqwe123", 465, true); //到服务器的SSL连接;
        $mail->setFrom("admin@shidexian.com");

        $send_mail = M("shop_config")->where(array("code"=>"order_send_wb_m"))->getField("value");
        $mail->setReceiver($send_mail);
        //$mail->setReceiver("GZ3send@163.com");
//        $mail->setReceiver("XXX@qq.com");
        $send_mail_c = M("shop_config")->where(array("code"=>"order_send_wb_c"))->getField("value");
        $send_mail_c = explode(",",$send_mail_c);
        foreach ($send_mail_c as $value){
            $mail->setCc($value);
        }
        //$mail->setCc("poptser@foxmail.com");
//        $mail->setCc("XXX@qq.com");
//        $mail->setBcc("XXX@qq.com");
//        $mail->setBcc("XXX@126.com");
        foreach ($file as $value){
            $mail->addAttachment($value);
        }
        $mail->setMail($title,$mailbody);
        $mail->sendMail();
    }
    /**
     * poptser 附带附件
     * 邮件发送
     */
    public function send_mail($mail_address=null,$title=null,$body=null,$file=null){
        if(empty($mail_address)||empty($title)||empty($file)){
            return false;
        }



        $mailbody = "
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<tbody><tr>
  <td bgcolor='#EFF2F7' align='center' style='padding:22px 0 36px 0;' class='padding5'>
  <table border='0' cellpadding='0' cellspacing='0' style='border-radius:4px; margin:0 auto; background-color:#ffffff' width='650' class='responsive-table'>
    <tbody>
    <tr>
      <td style='background-color:#ffffff; padding:0 50px 45px 50px;' class='padding1'>
        <table border='0' cellpadding='0' cellspacing='0' width='100%'>
           <tbody><tr>
             <td bgcolor='#ffffff' align='middle' style='background-color:#ffffff; font-size: 22px; color:#303C4B; font-weight:bold; padding:0 0 40px 0; line-height:32px;' colspan='2' class='padding4'>
               <span class='title' style='padding-bottom: 5px; border-bottom: 5px solid #ffd900;'>订单自动发送信息</span>
             </td>
          </tr>
          <tr>
             <td class='padding7' bgcolor='#ffffff' align='left' style='background-color:#ffffff; font-size: 15px; color:#4C5764; line-height:27px;' colspan='2'>
             相关内容请下载附件查看<br>
             为确保收到邮件，请将“admin@shidexian.com”加入白名单<br>
             </td>
          </tr>
        </tbody></table>
      </td>
    </tr>
        <tr>
      <td align='center' class='padding'>
        <table border='0' cellspacing='0' cellpadding='0' class='responsive-table'>
          <tbody><tr>
            <td>
              <span style='font-family:Hiragino Sans GB;font-size:16px;'>
              <a style='text-decoration:none;color:#ffffff;' href='##' target='_blank'>
               <div style='padding:10px 29px 10px 29px;border-radius:5px;text-align:center;text-decoration:none;background-color:#2bbdf8;color:#ffffff;font-size:20px;margin:0;white-space:nowrap'>食得鲜@广州优果蔬网络科技有限公司</div>
              </a>
              </span>
              <br>
            </td>
          </tr>
        </tbody></table>
      </td>
    </tr>
      </tbody></table>
    </td>
    </tr>
</tbody></table>
</td>
</tr>
</tbody></table>
                ";//邮件内容
        import('Vendor.smtp_new');
        $mail = new \MySendMail();
        $mail->setServer("smtp.ym.163.com", "admin@shidexian.com", "sdxqwe123", 465, true); //到服务器的SSL连接;
        $mail->setFrom("admin@shidexian.com");
        $send_mail_c = explode(",",$mail_address);
        foreach ($send_mail_c as $value){
            $mail->setReceiver($value);
        }
//        $mail->setReceiver("XXX@qq.com");
//        $mail->setCc("XXX@126.com");
//        $mail->setCc("XXX@qq.com");
//        $mail->setBcc("XXX@qq.com");
//        $mail->setBcc("XXX@126.com");
        foreach ($file as $value){
            $mail->addAttachment($value);
        }
        $mail->setMail($title,$mailbody);
        $mail->sendMail();
    }

    /**
     * 客服预警平台数据导出链接 后台
     */
    public function down_data(){
        set_time_limit(0);

        switch ($_GET['type']){
            case 1:
                $data_name = "未配货";
                break;
            case 8:
                $data_name = "未出仓";
                break;
            case 2:
                $data_name = "未配送";
                break;
            case 3:
                $data_name = "未送达";
                break;
            case 4:
                $data_name = "未自提";
                break;
            case 6:
                $data_name = "问题单";
                break;
            case 7:
                $data_name = "预售缺货";
                break;
            case 9:
                $data_name = "未回仓";
                break;
            case 10:
                $data_name = "订单超重";
                break;
            case 1001:
                $data_name = "未质检";
                break;
            default:
                exit("未知导出项，请确认");
        }

        if($_GET['type']==1001){

            $order_array = M("order_info")->where("shipping_status = 5 and order_status!=2 and quality_id=0 and add_time> 1500854400")->getField("order_sn",true);

        }else{
            $sql = "SELECT order_sn FROM  sdx_alarm_log2 WHERE type = {$_GET['type']} AND state= 0";
            $order_sn_array = M()->query($sql);
            $order_array =array();
            foreach ($order_sn_array as $key=>$value){
                $order_array[] = $value['order_sn'];
            }
        }


        $order_info = M()->query("SELECT o.*,
       wdr.name,zc.name as zcname,
       wdr.first_heavy,
       wdr.continued_heavy
  FROM `sdx_order_info` `o`,
       `sdx_warehouse_deliver_region` `wdr`,`sdx_zoning_cate` `zc`
 WHERE(
o.order_sn in (".implode(",",$order_array).")
   and o.wdr_id= wdr.id and wdr.zoning_id = zc.id and o.shipping_status !=2 and o.order_status !=2
   )
 GROUP BY order_id
 ORDER BY best_time_start");
        foreach ($order_info as $key=>$value){
            //$goods_info = A("Autoserver")->get_goods_list_real($value['order_id'],false,"name");
            $order_info[$key]['goods_name'] = str_replace("\n","<br/>",$goods_info['goods_name']);
            $order_info[$key]['goods_weight'] = $goods_info['goods_weight'];
            $order_info[$key]['goods_num'] = $goods_info['goods_num'];
            $order_info[$key]['address'] = A("Autoserver")->get_address_desc($value['province'], $value['city'], $value['district']).$value['address'].$value['address_name'];
            $order_info[$key]['best_time'] = date("Y-m-d H:i:s",$value['best_time']);
            $order_info[$key]['best_time_start'] = date("Y-m-d H:i:s",$value['best_time_start']);
            $goods_weight = ceil($goods_info['goods_weight']);  //商品重量
            if($goods_weight>3){
                //首重费用和续重费用
                $goods_weight_ext = $goods_weight-3;
                $order_info[$key]['distribution_cost'] = $value['first_heavy']+$value['continued_heavy']*$goods_weight_ext;
            }else{
                //仅首重费用
                $order_info[$key]['distribution_cost'] = $value['first_heavy'];

            }
            if($value['shipping_status']==2){
                $order_info[$key]['delayed_time'] = round(($value['confirm_time'] - $value['best_time'] + 28800)/3600,1);
                if ($order_info[$key]['delayed_time']<=0){
                    $order_info[$key]['delayed_time'] = "准时";

                    $order_info[$key]['order_d_time'] = "normal";
                }else{

                    $order_info[$key]['order_d_time'] = "late";
                }
            }else{
                $order_info[$key]['delayed_time'] = round(($value['best_time']-time())/3600,1);
                if ($order_info[$key]['delayed_time']<=0){
                    $order_info[$key]['delayed_time'] = "已超时";

                    $order_info[$key]['order_d_time'] = "late";
                }else{

                    $order_info[$key]['order_d_time'] = "normal";
                }
            }

            $order_info[$key]['otw'] = M("order_action")->
            where("action_note like '订单已出仓%' and order_id = ".$value['order_id'])->getField("action_user");
        }

        //下载
        import('Vendor.PHPExcel.PHPExcel');
        import('Vendor.PHPExcel.PHPExcel.Reader.Excel5');
        import('Vendor.PHPExcel.PHPExcel.IOFactory');
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->getProperties()->setCreator("shidexian@youguoshu")
            ->setLastModifiedBy("shidexian@youguoshu")
            ->setTitle("download file shidexian@youguoshu")
            ->setSubject("shidexian@youguoshu")
            ->setDescription("shidexian@youguoshu")
            ->setKeywords("shidexian")
            ->setCategory("shidexian");

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(10);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(5);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(5);
        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(60);
        $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(60);
        $objPHPExcel->getActiveSheet()->getStyle('A1:P1')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle( 'A1:P1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
        $objPHPExcel->getActiveSheet()->getStyle( 'A1:P1')->getFill()->getStartColor()->setARGB('FFF1A325');

        $objPHPExcel->getActiveSheet()->getStyle('A:P')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getPageSetup()->setHorizontalCentered(true);

        $styleArray = array(
            'borders' => array(
                'allborders' => array(
                    'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
                ),
            ),
        );

        $objPHPExcel->setActiveSheetIndex(0)
            //Excel的第A列，uid是你查出数组的键值，下面以此类推
            ->setCellValue('A1','订单编号')
            ->setCellValue('B1','条码')
            ->setCellValue('C1','产品名称')
            ->setCellValue('D1','规格(kg)')
            ->setCellValue('E1','数量')
            ->setCellValue('F1','运费')
            ->setCellValue('G1','客人姓名')
            ->setCellValue('H1','电话')
            ->setCellValue('I1','区域')
            ->setCellValue('J1','划区')
            ->setCellValue('K1','出仓员')
            ->setCellValue('L1','地址')
            ->setCellValue('M1','标志性建筑')
            ->setCellValue('N1','送达时间范围')
            ->setCellValue('O1','状态')
            ->setCellValue('P1','备注');
        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(30);
        $objPHPExcel->getActiveSheet()->getStyle('A1:P1')->applyFromArray($styleArray);

        $files = glob('Uploads/cache/*');
        foreach ($files as $file) {
            if (is_file($file)) {
                unlink($file);
            }
        }

        foreach ($order_info as $k => $v) {

            $cache_code = "Uploads/cache/".$v['order_id'].".jpg";
            $content = file_get_contents('http://qr.liantu.com/api.php?w=160&text='.$v['order_sn']);
            file_put_contents($cache_code, $content);


            switch ($v['shipping_status']){
                case 1:
                    $shipping_status = "已发货";
                    break;
                case 2:
                    $shipping_status = "收货确认";
                    break;
                case 5:
                    $shipping_status = "发货中";
                    break;
                case 0:
                    $shipping_status = "未货中";
                    break;
                default:
                    $shipping_status = "未知";
            }
            $num = $k + 2;
            $objPHPExcel->getActiveSheet()->getRowDimension($num)->setRowHeight(165);
            $objPHPExcel->getActiveSheet()->getStyle('A'.$num.':P'.$num)->applyFromArray($styleArray);
            $objPHPExcel->getActiveSheet()->getStyle('C'.$num)->getAlignment()->setWrapText(true);
            $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValueExplicit('A' . $num, $v['order_sn'],\PHPExcel_Cell_DataType::TYPE_STRING)
                ->setCellValue('C' . $num, str_replace("<br/>","\n",$v['goods_name']))
                ->setCellValueExplicit('D' . $num, $v['goods_weight'],\PHPExcel_Cell_DataType::TYPE_STRING)
                ->setCellValue('E' . $num, $v['goods_num'])
                ->setCellValue('F' . $num, $v['distribution_cost'])
                ->setCellValue('G' . $num, $v['consignee'])
                ->setCellValue('H' . $num, $v['mobile'])
                ->setCellValue('I' . $num, $v['name'])
                ->setCellValue('J' . $num, $v['zcname'])
                ->setCellValue('K' . $num, $v['otw'])
                ->setCellValue('L' . $num, $v['address'])
                ->setCellValue('M' . $num, $v['sign_building'])
                ->setCellValue('N' . $num, $v['best_time_start']."-".$v['best_time'])
                ->setCellValue('O' . $num, $shipping_status)
                ->setCellValue('O' . $num, $v['postscript']);

            $objDrawing[$num] = new \PHPExcel_Worksheet_Drawing();
            $objDrawing[$num]->setPath($cache_code);
            $objDrawing[$num]->setHeight(160);//照片高度
            $objDrawing[$num]->setWidth(160); //照片宽度
            $objDrawing[$num]->setOffsetX(5);
            $objDrawing[$num]->setOffsetY(5);
            $objDrawing[$num]->setCoordinates('B'.$num);
            $objDrawing[$num]->setWorksheet($objPHPExcel->getActiveSheet());
        }
        $line_num = $num+1;
        $objPHPExcel->getActiveSheet()->mergeCells('A'.$line_num.':P'.$line_num);
        $objPHPExcel->getActiveSheet()->setCellValue('A'.$line_num, "食得鲜订单信息");
        $objPHPExcel->getActiveSheet()->getStyle('A'.$line_num)->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->setTitle('User');
        $objPHPExcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="shidexian.xls"');
        header('Cache-Control: max-age=0');
        $write = new \PHPExcel_Writer_Excel5($objPHPExcel);
        $write->save('php://output');
        exit;
    }
}